package com.baishui.gateway.handler;

import com.baishui.gateway.exception.GateWayException;
import com.baishui.gateway.context.GateWayRouteContext;
import com.baishui.gateway.context.GateWayRouteContextHelper;
import io.vertx.ext.web.RoutingContext;

public abstract class AbstractHandler extends BaseHandler {

    @Override
    public void handle(RoutingContext routingContext) {
        GateWayRouteContext context = GateWayRouteContextHelper.getContext(routingContext);
        try {
            handle(context, routingContext);
        } catch (Throwable throwable) {
            if (throwable instanceof GateWayException) {
                log.error("... error..", throwable);
                String throwableMessage = throwable.getMessage();
                writeError(routingContext);
            }
        }
    }

    abstract void handle(GateWayRouteContext context, RoutingContext routingContext) throws GateWayException;
}
